/*
 * redmicro all Copyright (c)
 *
 * Created by seeker910 on 2015/11/17.
 */
Rsd.define('Rsd.Faith.pages.BizZiJinShiYongHuaBoListPage', {
    extend: 'Rsd.Faith.pages.ListPage',
    requires: [  'Rsd.Faith.controls.XiaoQuInput', 'Rsd.Faith.controls.SuoShuQiInput'],
    xtype: 'list-huaBo',
    border: false,
    tabTitle: '资金使用已划拨列表',
    formTitle:'资金使用划拨',
    titleField:'shenqingdanhao',
    sort:[{name:'HuaBoRiQi',direction:'desc'}],
    searchColumns:[
        {name:'SuoShuQi',text:'所属期',width:250,xtype:'ctrl-suoshuqi'},
        {name:'ShenQingDanHao',text:'申请单号',width:250},
        {name:'XiaoQuBianHao',text:'小区编号',width:250},
        {name:'ZhuangTai',text:'状态',width:250, "xtype": "combobox-enum", "enum":"Rsd.Faith.Core.ZiJinHuaBoZhuangTai"}
        ],
    "modelType": "UsingZiJinShiYongHuaBoBiaoModel",
    "formFields": [
        {
            "name": "ShenQingDanHao",
            "label": {
                "text": "申请单号",
                "width": 80
            },
            "index": 0,
            readOnly:true,
            "xtype": "text"
        },
        {
            "name": "XiaoQuBianHao",
            "label": {
                "text": "小区编号",
                "width": 80
            },
            "index": 0,
            readOnly:true,
            "xtype": "text"
        },

        {
            "name": "HuaBoBianHao",
            "label": {
                "text": "划拨编号",
                "width": 80
            },
            "index": 0,
            "xtype": "text"
        },
        {
            "name": "HuaBoRiQi",
            "label": {
                "text": "划拨日期",
                "width": 80
            },
            "index": 0,
            "xtype": "date",
            "formatString": "yyyy-MM-dd"
        },
        {
            "name": "SuoShuQi",
            "label": {
                "text": "所属期",
                "width": 120
            },
            readOnly:true,
            "xtype": "text"
        },
        {
            "name": "HuaBoFangShi",
            "label": {
                "text": "划拨方式",
                "width": 80
            },
            "index": 0,
            "xtype": "combobox-enum",
            "enum":"Rsd.Faith.Core.BoFuFangShi",
        },
        {
            "name": "HuaBoJinE",
            "label": {
                "text": "划拨金额",
                "width": 80
            },
            "index": 0,
            "xtype": "number",
            "precision": 2
        },
        {
            "name": "ShenPiRen",
            "label": {
                "text": "审批人",
                "width": 80
            },
            "index": 0,
            "xtype": "text"
        },
        {
            "name": "ZhuangTai",
            "label": {
                "text": "状态",
                "width": 80
            },
            "index": 0,
            readOnly:true,
            "xtype": "combobox-enum",
            "enum":   "Rsd.Faith.Core.ZiJinHuaBoZhuangTai"
        },
        {
            "name": "Remark",
            "label": {
                "text": "备注",
                "width": 80
            },
            "dataindex": "remark",
            "index": 200,
            "xtype": "text"
        }
    ],
    "gridColumns": [
        {
            "text": "序号",
            "xtype": "index",
            "width": 40,
            "sortable": true,
            "index": 0
        },

        {
            "name": "ShenQingDanHao",
            "text": "申请单号",
            "sortable": true,
            "format":"zhuangtaiFormat",
            "index": 0,
            "width": 100,
            "nobr": true
        },
        {
            "name": "SuoShuQi",
            "dataIndex": "SuoShuQi",
            "sortable": false,
            "text": "所属期",
            align:'center',
            "index": 20,
            "exist": true,
            "xtype": "string",
            "width": 80,
            "nobr": true
        },
        {
            "name": "XiaoQuBianHao",
            "text": "小区",
            "sortable": true,
            "xtype": "ctrl-xiaoqu",
            "index": 0,
            "width": 100,
            "nobr": true
        },
      /*  {
            "name": "LouDongHao",
            "text": "楼栋号",
            "sortable": true,
            "index": 0,
            "width": 70,
            "nobr": true
        },*/
        {
            "name": "HuaBoBianHao",
            "text": "划拨编号",
            "sortable": true,
            "index": 0,
            "width": 100,
            "nobr": true
        },
        {
            "name": "HuaBoRiQi",
            "text": "划拨日期",
            "sortable": true,
            "index": 0,
            "xtype": "date",
            "formatString": "yyyy-MM-dd",
            "width": 100
        },
        {
            "name": "HuaBoJinE",
            "text": "划拨金额",
            "sortable": true,
            "index": 0,
            "xtype": "number",
            "width": 100,
            "precision": 2
        },
        {
            "name": "HuaBoFangShi",
            "text": "划拨方式",
            "sortable": true,
            "index": 0,
            "width": 70,
            "xtype": "enum",
            "enum": {
                "name": "Rsd.Faith.Core.BoFuFangShi",
                "valueMember": "code",
                "items": [
                    {
                        "code": "WZ",
                        "value": 0,
                        "text": "未知"
                    },
                    {
                        "code": "ZZ",
                        "value": 1,
                        "text": "转账"
                    },
                    {
                        "code": "XJ",
                        "value": 2,
                        "text": "现金"
                    },
                    {
                        "code": "ZP",
                        "value": 3,
                        "text": "支票"
                    }
                ]
            },
            align:'center',
            "nobr": true
        },
        {
            "name": "FuKuanZhangHu",
            "dataIndex": "FuKuanZhangHu",
            "sortable": false,
            "text": "付款账户",
            "index": 27,
            "exist": true,
            "xtype": "enum",
            "enum": {
                "name": "Rsd.Faith.Core.FuKuanZhangHu",
                "valueMember": "code",
                "items": [
                    {
                        "code": "BJ",
                        "value": 0,
                        "text": "资金本金账户"
                    },
                    {
                        "code": "TC",
                        "value": 1,
                        "text": "资金统筹账户"
                    },
                    {
                        "code": "XQTC",
                        "value": 2,
                        "text": "小区统筹账户"
                    },
                    {
                        "code": "LDTC",
                        "value": 3,
                        "text": "小区楼栋统筹账户"
                    },
                    {
                        "code": "DYTC",
                        "value": 4,
                        "text": "小区单元统筹账户"
                    }
                ]
            },
            "width": 150,
            "nobr": true
        },
        {
            "name": "ShenPiRen",
            "text": "审批人",
            "sortable": true,
            "index": 0,
            "width": 70,
            "nobr": true
        },
        {
            "name": "ZhuangTai",
            "text": "状态",
            "sortable": true,
            "index": 0,
            "width": 150,
            "xtype": "enum",
            "enum": {
                "name": "Rsd.Faith.Core.ZiJinHuaBoZhuangTai",
                "valueMember": "code",
                "items": [
                    {
                        "code": "DJ",
                        "value": 0,
                        "text": "已划拨,待分摊 "
                    },
                    {
                        "code": "FT",
                        "value": 1,
                        "text": "已分摊,待入账 "
                    },
                    {
                        "code": "RZ",
                        "value": 2,
                        "text": "已入账"
                    }
                ]
            },
            align:'center',
            "nobr": true
        },
        {
            "name": "Remark",
            "text": "备注",
            "sortable": true,
            "index": 200,
            "width": 150,
            "nobr": true
        }
    ],
    templateCols: [
        {
            name: 'space',
            text: '',
            xtype: 'template',
            width: 5,
            hideable: false,
            sortable: false
        }
    ],
    /*
     * */
    constructor: function (config) {
        config = config || {};
        Rsd.apply(this, config);
    },


    /*
     * */
    zhuangtaiFormat:function templateFormat(row){

        var  btn =  Rsd.button(' 分 摊 ',function(){
            var page = Rsd.create('Rsd.Faith.dialogs.BizZiJinShiYongFenTanDialog',{data:row});
            page.showDialog();
        });


        var  btnView = document.createElement('a');
        btnView.href='#';
        btnView.title ="查看已分摊明细信息"
        btnView.innerHTML = '查看明细';
        $(btnView).click (function(){
            var page = Rsd.create('Rsd.Faith.dialogs.BizZiJinShiYongFenTanViewDialog',{readOnly:true,data:row});
            page.showDialog();
        });

        var  btnCancel = document.createElement('a');
        btnCancel.href='#';
        btnCancel.title ="重新对使用费用进行分摊";
        if(Rsd.isEmpty(row['ShenQingDanHao']))
        {
            btnCancel.innerHTML = '[申请单号未空]';
            btnCancel.style.color='red';
        }
        else {
            btnCancel.innerHTML = '重新分摊';
            $(btnCancel).click (function(){
                var page = Rsd.create('Rsd.Faith.dialogs.BizZiJinShiYongFenTanDialog',{data:row});
                page.showDialog();
            });
        }

        var  btnOk = Rsd.button(' 入 帐 ',function(){
                var page = Rsd.create('Rsd.Faith.dialogs.BizZiJinShiYongFenTanViewDialog',{data:row});
                page.showDialog();
        });

        if(row['ZhuangTai']=='FT')
        {
            return [Rsd.newLine(),btnOk,Rsd.blankspan(),btnCancel] ;
        }
        if(row['ZhuangTai']=='RZ')
        {
            return [Rsd.newLine(),btnView] ;
        }
        return [Rsd.newLine(),btn];

    }

});

